
import { UserInfo,userInfo } from '@/api'
import { clearToken } from '@/utils'
import { RootThunkAction } from '.'

// 基础模板
export type userInfoType = {
  type: 'user/info'
  info: UserInfo
}

function userInfoAction(): RootThunkAction {
  return async (dispatch) => {
    // 发送请求
    const res = await userInfo()
    dispatch({
      type:'user/info',
      info:res.data.data
    })
  }
}
function loginOutAction(): RootThunkAction {
  return async (dispatch) => {
    // 发送请求
    clearToken()
    dispatch({
      type:'user/info',
      info:{} as UserInfo
    })
  }
}

export { userInfoAction ,loginOutAction}
